package com.oss.Intercept;

import java.sql.Timestamp;
import java.util.Date;

// import org.joda.time.DateTime;
import com.eova.aop.AopContext;
import com.eova.aop.MetaObjectIntercept;
import com.eova.common.utils.xx;
/*
import com.eova.config.EovaConst;
import com.eova.model.User;
import com.jfinal.core.Controller;
*/

public class aj_wgxx extends MetaObjectIntercept {
	// 
	public String tableName = "aj_wgxx";
	public String className = "com.oss.Intercept." + tableName;
	
	@Override
	 
	public void queryBefore(AopContext ac) throws Exception {
		// 网格信息
		String method = "queryBefore";
		String prompt = className + "." + method + ">";
		System.out.println(prompt + "start ...");
		
		String user_id = InterceptUtil.getUserID(ac);
		String name = "";



		System.out.println(prompt +  "login_id=[" + user_id + "]");
		int i = 0;
		
		if ( (!user_id.equals("1")) && (!user_id.equals("2")) && (!user_id.equals("3")) && (!user_id.equals("4")) ) {
			System.out.println(prompt +  "不是管理员,需要限制!");
			while (true) {
				name = ac.ctrl.getPara(i);
				System.out.println(prompt +  "name(" + String.valueOf(i) + ")=[" + name + "]");
				if ( name.indexOf("c_" + tableName) != -1 ) {
					ac.condition = " and xid like (select xid from pt_user where id = '" + user_id + "')||'%'";
					 
					System.out.println(prompt +  "ac.condition=[" + ac.condition + "]");
					break;
				} else {
					if (xx.isEmpty(name)) {
						break;
					}
				}
		        i++;			
			}
			
		} else {
			System.out.println(prompt +  "是管理员,不需要限制!");
		}
			
		
		/*
		if (!xx.isEmpty(name)) {
			ac.condition = " state = " + name;
		}
		*/
		
		// 同理：想添加自定义查询条件，直接添加元字段
		// 然后配置为 可查询，禁止编辑，禁止新增，然后获取值
		// 利用本AOP方法可自定义查询sql即可
		// 应用场景：like or 子查询 范围查询 外表关联查询...
		System.out.println(prompt +  "end.");
	}

	
}

